// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Nuclear weapon with ACE
// -----------------------------------------------

private [
	"_position",
	"_unit",
	"_nuclearammo",
	"_array",
	"_marker"
];

_unit        = _this select 0;
_nuclearammo = _this select 1;

if (count _this == 1) then {_nuclearammo = 1};

diag_log "NUCLEAR FIRE WAS LAUNCHED";

while {((getDammage _unit < 0.7) and (_nuclearammo > 0))} do {
	_position = position (wctownlocations call BIS_fnc_selectRandom);
	_position = [_position] call WC_fnc_relocateposition;
	while {_position distance getMarkerPos "respawn_west" < 2000} do {
		_position = position (wctownlocations call BIS_fnc_selectRandom);
		_position = [_position] call WC_fnc_relocateposition;
		sleep 0.05;
	};

	wcbomb = true;
	["wcbomb", "client"] call WC_fnc_publicvariable;
	wcmessageW = [format [localize "STR_WC_MESSAGEMISSIONCOMMANDEMENT", wclevel], "NUCLEAR BOMBING TAKE COVER"];
	["wcmessageW", "client"] call WC_fnc_publicvariable;

	// Create nuclear marker
	_marker = [format ['nuclear%1', wcnuclearindex], 500, _position, "ColorOrange", "ELLIPSE", "FDIAGONAL", "", 0, "", false] call WC_fnc_createmarker;
	wcnuclearindex = wcnuclearindex + 1;

	sleep (random 240);

	_array = _position nearEntities [["All"], 500];
	{
		_x setDamage (0.5 + random 0.5);
	} foreach _array;

	wcnewnuclearzone = _position;
	["wcnewnuclearzone", "client"] call WC_fnc_publicvariable;
	wcnuclearzone = wcnuclearzone + [_position];
	["wcnuclearzone", "client"] call WC_fnc_publicvariable;
	_nuclearammo = _nuclearammo - 1;
	sleep (240 + random 240);
};